// 用户名判断
function change_user() {
    var olduser = document.getElementById("olduser").value;
    var user = document.getElementById("user").value;
    if (olduser == null || olduser == "") {
        document.getElementById("tips_usr").innerHTML = "用户名不能为空！！！";
        return false;
    }
    if (user == null || user == "") {
        document.getElementById("tips_usr").innerHTML = "新用户名不能为空！！！";
        return false;
    }
    if (user.length > 10) {
        document.getElementById("tips_usr").innerHTML = "用户名不能超过10位！！！";
        return false;
    }
    if (olduser != null && olduser != ""&&user != null && user != "") {
        // 1.创建对象
        const xhr = new XMLHttpRequest();
        // 3.初始化 设置请求方法和url
        xhr.open('GET', 'changePwd.action?action=ajaxUser&&olduser=' + olduser+'&&user='+user, true);
        // 4.发送
        xhr.send();
        // 2.事件绑定，待接收服务端结果
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status >= 200 && xhr.status < 300) {
                if (xhr.response) {
                    document.getElementById("tips_usr").innerHTML = xhr.response;
                    return false;
                } else {
                    document.getElementById('form_user').action = "changePwd.action?action=changeUsr";
                    document.getElementById('form_user').submit();
                    return true;
                }
            }
        }
    }
}

// 密码判断
function change_pwd() {
    var oldpwd = document.getElementById("oldpwd").value;
    var pwd = document.getElementById("pwd").value;
    var repwd = document.getElementById("repwd").value;
    if (oldpwd == null || oldpwd == "") {
        document.getElementById("tips_pwd").innerHTML = "密码不能为空！！！";
        return false;
    }
    if (pwd == null || pwd == "") {
        document.getElementById("tips_pwd").innerHTML = "新密码不能为空！！！";
        return false;
    }
    if (repwd == null || repwd == "") {
        document.getElementById("tips_pwd").innerHTML = "重复密码不能为空！！！";
        return false;
    }
    if (pwd != repwd) {
        document.getElementById("tips_pwd").innerHTML = "两次输入新密码不一致！！！";
        return false;
    }
    if (oldpwd != null && oldpwd != "") {
        // 1.创建对象
        const xhr = new XMLHttpRequest();
        // 3.初始化 设置请求方法和url
        xhr.open('GET', 'changePwd.action?action=ajaxPwd&&oldpwd=' + oldpwd, true);
        // 4.发送
        xhr.send();
        // 2.事件绑定，待接收服务端结果
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status >= 200 && xhr.status < 300) {
                if (xhr.response) {
                    document.getElementById("tips_pwd").innerHTML = xhr.response;
                    return false;
                } else {
                    document.getElementById('form_pwd').action = "changePwd.action?action=changePwd";
                    document.getElementById('form_pwd').submit();
                    return true;
                }
            }
        }
    }
}